{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "be85cec0-7f9d-46b1-bcc4-e4ca7926ecb8",
   "metadata": {},
   "source": [
    "# Find Challenging Cases In Any Huggingface Dataset"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "448426d8-2268-4115-b4a3-b7bd74fbbda0",
   "metadata": {},
   "source": [
    "First, install sliceguard including its embedding and AutoML capabilities."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5900c6f3-eae3-4693-9e77-7e40bd1cc426",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install sliceguard[all]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "adf7c23e-088a-4351-9436-8c5522cb9c53",
   "metadata": {},
   "source": [
    "Import sliceguard and a metric function that is meaningful for the task of audio classification."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c367734a-9c3f-4bc0-97c1-59f074aae77f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sliceguard import SliceGuard\n",
    "from sliceguard.data import from_huggingface\n",
    "from sklearn.metrics import accuracy_score"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0c00050-9ce9-4a0c-9d57-799978b0e2bc",
   "metadata": {},
   "source": [
    "Load an audio classification dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f429e2b9-20c3-4bb4-a198-93998b2f9a68",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = from_huggingface(\"renumics/emodb\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "137ef177-f469-4179-80be-143c9245d87d",
   "metadata": {},
   "outputs": [],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8caa110e-2e0b-474c-a724-78a488384c2a",
   "metadata": {},
   "source": [
    "Detect challenging clusters using sliceguard."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c4419fd-79a8-46db-83c3-4b613be22b1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "sg = SliceGuard()\n",
    "sg.find_issues(df, features=[\"audio\"], y=\"emotion\", metric=accuracy_score)\n",
    "sg.report()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb190e94-6148-4c09-8426-02192e21ab40",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
